using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using csvviewer.contracts;

namespace csvviewer.logic
{
    public class Buffer_lines : IDependsOn<ConcurrentList<long>>
    {
		private int _lineCount;
		
        public void Process(long linePosition)
        {
			if (linePosition >= 0)
			{
				_lineBuffer.Add(linePosition);
				_lineCount++;
			}
			
			if (_lineCount % 500 == 0 || 
				(linePosition < 0 && _lineCount < 500))
				this.Continue(PageDirections.First);
        }

        public event Action<PageDirections> Continue;


        private ConcurrentList<long> _lineBuffer; 

        public void Inject(ConcurrentList<long> dependency)
        {
            _lineBuffer = dependency;
        }
    }
}
